package com.jt.provider.controller;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
@Component
public class DefaultRequestOriginParser implements RequestOriginParser {
    /**这个方法基于业务规则对请求数据进行解析*/
    @Override
    public String parseOrigin(HttpServletRequest request) {
        //对请求参数进行解析,并返回参数值，然后将这个值应用在sentinel的....
        //String origin = request.getParameter("origin");
        //return origin;
        //进行请求头中的数据进行解析，请求的名字为token,然后基于获取的ip值进行授权
        //String token = request.getHeader("token");
        //return token;
        //对请求ip地址进行解析,然后进行授权
        String ip = request.getRemoteAddr();
        System.out.println("ip="+ip);
        return ip;
    }
}
